﻿using System;
using System.ServiceModel;

namespace FileMonitor.Service.StateProvider
{
    public class StateProvider:IDisposable
    {
        public readonly static StateProvider Instance=new StateProvider();
        private static ServiceHost host;

        private StateProvider()
        {
            host = new ServiceHost(typeof(StateProviderService));
        }

        public void StartService() 
        {
            if (host.State == CommunicationState.Created||host.State==CommunicationState.Closed)
            {
                host.Open();
            }
        }

        public void StopService()
        {
            if (host.State == CommunicationState.Opened)
            {
                host.Close();
            }
        }

        public void Dispose()
        {
            (host as IDisposable).Dispose();
        }

    }
}
